unit Unit_Defaults;
interface
uses
  OpenGL, Windows, OpenAL, SysUtils, Graphics, KromUtils;

function GetPresetColor(ID:integer):TColor;
procedure SetPresetColorGL(ID:integer; A:single);

//STKit2 constants
const
  VersionInfo       = 'Scenery ToolKit 2.3.6           (05 Aug 2010)';
  FPS_INTERVAL      = 1000;    //Calculate FPS every ---- ms
  STKit2_Data_Path  = 'STKit2 Data';

  MaxObjInst        = 10000;               //Limit on object instances in theory is 65k
  MaxSNI            = 300;                 //256 in fact I reserve 44 for Spawn routes
  MaxSNINodes       = MaxSNI*5+100;        //number of SNI nodes
  MaxGrounds        = 12;                  //Limit is 12, tested by Curry
  MAX_TRACKS        = 32;
  MAX_WP_TRACKS     = 32;

  MAX_LIGHTS        = 2048;                 //Maximum Lights count

  MAX_BLOCKS_X      = 200;                  //How many blocks scenery can ahve in length (/102,4 = km)
  MAX_BLOCKS_Z      = 200;                  //Keeping in mind that max scenery size is 4096 blocks (*16 = 65k sub-block)
  MAX_BLOCK_COUNT   = 4096;

  MAX_LWO_LAYERS    = 1024;                 //Maximum allowed LWO layers

  DONT_TRACE_TAG    = 1234567;             //Special tag to exclude certain polys from certain checks
                                           //(e.g. shadow tracing for backdrop grid of scenery)    


type TEditingFormat = (ef_WR2, ef_N, ef_CT, ef_BW);

type RenderModeTypes=(rmSchem=0,
                      rmBlend=1,
                      rmFlat=2,
                      rmOpenGL=3,
                      rmShader=4,
                      rmFull=5,
                      rmPrev=6);

type TActivePage=(
    apLWO,
    apGrounds,
    apTextures,
    apMaterials,
    apObjects,
    apSounds,
    apLights,
    apStructure,

    apTracksMT,
    apTracksAR,
    apTracksWP,
    apTOB,
    apStreets,
    apAnimated,
    apSky,
    apGrass,
    apTriggers,
    apAddonInfo);

TTexSend=(ts_AddTex,ts_RenTex);

TMouseAction = (tmaNone, tmaMove, tmaRotate, tmaZoom);
TEditingMode = (emNone, emTrigger, emTriggerDest, emStreetNode, emStreetAnchor, emStreetAnchorLength, emStreetSpline);

const
BArrow:array[1..8,1..3]of single =(
(0,-0.50,-0.25),(0,-0.29,-0.25),(0, 0, 0.05),(0, 0, 0.25), //
(0, 0, 0.25),(0, 0, 0.05),(0, 0.29,-0.25),(0, 0.50,-0.25));  //

BBox:array[1..8,1..3]of single =(
(-0.5,-0.5,-0.5),( 0.5,-0.5,-0.5),( 0.5, 0.5,-0.5),(-0.5, 0.5,-0.5),
(-0.5,-0.5, 0.5),( 0.5,-0.5, 0.5),( 0.5, 0.5, 0.5),(-0.5, 0.5, 0.5));

BBoxI:array[1..6,1..4]of byte =((4,3,2,1),(5,6,7,8),(1,2,6,5),(2,3,7,6),(3,4,8,7),(4,1,5,8));

WheelsM:array[1..4,1..4]of shortint =(
(-1,+1,-1,-1),(-1,-1,-1,+1),  //Front
(+1,+1,+1,-1),(+1,-1,+1,+1)); //Rear

ShadQty=19; ObjShadQty=1;

MatModeV:array[1..ShadQty]of string = (
'','','','','','','','','','','','','','','','',
'','',''); //corresponding filename & index FRAG

MatModeF:array[1..ShadQty]of string = (
'Mat_000','Mat_016','Mat_032','Mat_048','Mat_064','Mat_080','Mat_096','Mat_112',
'Mat_128','Mat_144','Mat_160','Mat_176','Mat_192','Mat_208','Mat_224','Mat_240',
'Mat_Blend','Mat_Smoothshade','Mat_Materials'); //corresponding filename & index FRAG

MatModeDefaultV:string=
  'varying vec3 kBlend; '+
  'void main(void) '+
  '{ kBlend = gl_SecondaryColor.rgb; '+
  'gl_Position = ftransform();}';

MatModeDefaultF:string=
  'varying vec3 kBlend; '+
  'void main(void) '+
  '{ vec3 kColor = smoothstep(0.4375,.5625,kBlend.rgb); '+
  'gl_FragColor = vec4(kColor.rgb,1);}';

ObjMover:array[1..6,1..3]of single=
((-5,0,0),(5,0,0),(4,0,-0.5),(5,0,0),(4,0,0.5),(5,0,0));

PresetColor:Array[1..30,1..3] of byte = (
//Light colors
(255,108,108),(255,182,108),(255,255,108),//Red,Orange,Yellow
(108,255,108),(108,255,255),(108,182,255),//Green,Cyan,Blueish
(108,108,255),(182,108,255),(255,108,255),//Blue,Violet,Pink
//Dark colors
(170,  0,  0),(170, 84,  0),(170,170,  0),//Red,Orange,Yellow
(  0,170,  0),(  0,170,170),(  0, 84,170),//Green,Cyan,Blueish
(  0 , 0,170),( 84,  0,170),(170,  0,170),//Blue,Violet,Pink
//Medium colors
(255,  0,  0),(255,128,  0),(255,255,  0),//Red,Orange,Yellow
(  0,255,  0),(  0,255,255),(  0,128,255),//Green,Cyan,Blueish
(  0,  0,255),(128,  0,255),(255,  0,255),//Blue,Violet,Pink
//Grey colors
(208,208,208),(144,144,144),( 84, 84, 84));//Light,Medium,Dark

ObjTypes1:array[0..8]of byte = (0,3,4,5,6,7,8,16,17);
ObjTypes1inv:array[0..17]of byte = (0,0,0,1,2,3,4,5,6,0,0,0,0,0,0,0,7,8);

PageCaption:array[TActivePage] of string = (
'[LW] Convert LWO to Scenery',
'[GR] Grounds setup',
'[TX] Textures',
'[MT] Materials',
'[OB] Objects',
'[SN] Sounds',
'[LI] Lights',
'[ST] Structure info',
'[TRK-MT] Tracks - Make track',
'[TRK-AR] Tracks - Direction arrows',
'[TRK-WP] Tracks - Waypoints',
'[TOB] Track objects',
'[STR] Traffic streets',
'[SNI] Animated objects',
'[SKY] Skies setup',
'[RO#] Grass',
'[TRL] Triggers',
'[SC2] Addon description');

PageShortcut:Array[1..16] of string = (
'LW','GR','TX','MT','OB','SN','LI','ST',
'TRK','TOB','STR','SNI','SKY','RO#','TRL','SC2');


OSphere:array[1..92,1..3]of single =(
(0,5,0),(1.715,4.663,0.557),(0,4.663,1.804),(3.2,3.699,1.04),(1.784,3.973,2.456),
(0,3.699,3.364),(4.253,2.236,1.382),(3.2,2.584,2.843),(1.715,2.584,3.922),(0,2.236,4.472),
(1.06,4.663,-1.459),(1.978,3.699,-2.722),(2.887,3.973,-0.938),(2.629,2.236,-3.618),(3.693,2.584,-2.165),
(4.26,2.584,-0.42),(-1.06,4.663,-1.459),(-1.978,3.699,-2.722),(0,3.973,-3.035),(-2.629,2.236,-3.618),
(-0.917,2.584,-4.181),(0.917,2.584,-4.181),(-1.715,4.663,0.557),(-3.2,3.699,1.04),(-2.887,3.973,-0.938),
(-4.253,2.236,1.382),(-4.26,2.584,-0.42),(-3.693,2.584,-2.165),(-1.784,3.973,2.456),(-1.715,2.584,3.922),
(-3.2,2.584,2.843),(0,-5,0),(1.06,-4.663,1.459),(1.715,-4.663,-0.557),(1.978,-3.699,2.722),
(2.887,-3.973,0.938),(3.2,-3.699,-1.04),(2.629,-2.236,3.618),(3.693,-2.584,2.165),(4.26,-2.584,0.42),
(4.253,-2.236,-1.382),(0,-4.663,-1.804),(1.784,-3.973,-2.456),(0,-3.699,-3.364),(3.2,-2.584,-2.843),
(1.715,-2.584,-3.922),(0,-2.236,-4.472),(-1.715,-4.663,-0.557),(-1.784,-3.973,-2.456),(-3.2,-3.699,-1.04),
(-1.715,-2.584,-3.922),(-3.2,-2.584,-2.843),(-4.253,-2.236,-1.382),(-1.06,-4.663,1.459),(-2.887,-3.973,0.938),
(-1.978,-3.699,2.722),(-4.26,-2.584,0.42),(-3.693,-2.584,2.165),(-2.629,-2.236,3.618),(0,-3.973,3.035),
(-0.917,-2.584,4.181),(0.917,-2.584,4.181),(1.06,0.78,4.824),(2.887,0.938,3.973),(1.978,-0.78,4.526),
(4.26,0.78,2.499),(3.693,-0.78,3.279),(4.915,0.78,0.482),(4.671,0.938,-1.518),(4.915,-0.78,-0.482),
(3.693,0.78,-3.279),(4.26,-0.78,-2.499),(1.978,0.78,-4.526),(0,0.938,-4.911),(1.06,-0.78,-4.824),
(-1.978,0.78,-4.526),(-1.06,-0.78,-4.824),(-3.693,0.78,-3.279),(-4.671,0.938,-1.518),(-4.26,-0.78,-2.499),
(-4.915,0.78,0.482),(-4.915,-0.78,-0.482),(-4.26,0.78,2.499),(-2.887,0.938,3.973),(-3.693,-0.78,3.279),
(-1.06,0.78,4.824),(-1.978,-0.78,4.526),(4.671,-0.938,1.518),(2.887,-0.938,-3.973),(-2.887,-0.938,-3.973),
(-4.671,-0.938,1.518),(0,-0.938,4.911));

OSphereN:array[1..92,1..3]of single =(
(0,1,0),(0.336,0.936,0.109),(0,0.936,0.353),(0.646,0.734,0.21),(0.357,0.795,0.491),
(0,0.734,0.679),(0.851,0.447,0.276),(0.646,0.516,0.563),(0.336,0.516,0.788),(0,0.447,0.894),
(0.208,0.936,-0.286),(0.399,0.734,-0.549),(0.577,0.795,-0.188),(0.526,0.447,-0.724),(0.735,0.516,-0.44),
(0.853,0.516,-0.076),(-0.208,0.936,-0.286),(-0.399,0.734,-0.549),(0,0.795,-0.607),(-0.526,0.447,-0.724),
(-0.191,0.516,-0.835),(0.191,0.516,-0.835),(-0.336,0.936,0.109),(-0.646,0.734,0.21),(-0.577,0.795,-0.188),
(-0.851,0.447,0.276),(-0.853,0.516,-0.076),(-0.735,0.516,-0.44),(-0.357,0.795,0.491),(-0.336,0.516,0.788),
(-0.646,0.516,0.563),(0,-1,0),(0.208,-0.936,0.286),(0.336,-0.936,-0.109),(0.399,-0.734,0.549),
(0.577,-0.795,0.188),(0.646,-0.734,-0.21),(0.526,-0.447,0.724),(0.735,-0.516,0.44),(0.853,-0.516,0.076),
(0.851,-0.447,-0.276),(0,-0.936,-0.353),(0.357,-0.795,-0.491),(0,-0.734,-0.679),(0.646,-0.516,-0.563),
(0.336,-0.516,-0.788),(0,-0.447,-0.894),(-0.336,-0.936,-0.109),(-0.357,-0.795,-0.491),(-0.646,-0.734,-0.21),
(-0.336,-0.516,-0.788),(-0.646,-0.516,-0.563),(-0.851,-0.447,-0.276),(-0.208,-0.936,0.286),(-0.577,-0.795,0.188),
(-0.399,-0.734,0.549),(-0.853,-0.516,0.076),(-0.735,-0.516,0.44),(-0.526,-0.447,0.724),(0,-0.795,0.607),
(-0.191,-0.516,0.835),(0.191,-0.516,0.835),(0.208,0.163,0.965),(0.577,0.188,0.795),(0.399,-0.163,0.902),
(0.853,0.163,0.496),(0.735,-0.163,0.658),(0.982,0.163,0.101),(0.934,0.188,-0.304),(0.982,-0.163,-0.101),
(0.735,0.163,-0.658),(0.853,-0.163,-0.496),(0.399,0.163,-0.902),(0,0.188,-0.982),(0.208,-0.163,-0.965),
(-0.399,0.163,-0.902),(-0.208,-0.163,-0.965),(-0.735,0.163,-0.658),(-0.934,0.188,-0.304),(-0.853,-0.163,-0.496),
(-0.982,0.163,0.101),(-0.982,-0.163,-0.101),(-0.853,0.163,0.496),(-0.577,0.188,0.795),(-0.735,-0.163,0.658),
(-0.208,0.163,0.965),(-0.399,-0.163,0.902),(0.934,-0.188,0.304),(0.577,-0.188,-0.795),(-0.577,-0.188,-0.795),
(-0.934,-0.188,0.304),(0,-0.188,0.982));

OSphereP:array[1..180,1..3]of byte = (
(2,1,3),(4,2,5),(6,5,3),(5,2,3),(7,4,8),(8,5,9),(10,9,6),(8,4,5),(9,5,6),(11,1,2),
(12,11,13),(4,13,2),(13,11,2),(14,12,15),(15,13,16),(7,16,4),(15,12,13),(16,13,4),(17,1,11),(18,17,19),
(12,19,11),(19,17,11),(20,18,21),(21,19,22),(14,22,12),(21,18,19),(22,19,12),(17,23,1),(24,23,25),(18,25,17),
(25,23,17),(26,24,27),(28,27,25),(20,28,18),(27,24,25),(28,25,18),(23,3,1),(6,3,29),(24,29,23),(29,3,23),
(10,6,30),(31,30,29),(26,31,24),(30,6,29),(31,29,24),(32,34,33),(33,36,35),(34,37,36),(34,36,33),(35,39,38),
(36,40,39),(37,41,40),(36,39,35),(36,37,40),(32,42,34),(34,43,37),(42,44,43),(42,43,34),(37,45,41),(43,46,45),
(44,47,46),(43,45,37),(43,44,46),(32,48,42),(42,49,44),(48,50,49),(42,48,49),(44,51,47),(49,52,51),(50,53,52),
(49,51,44),(49,50,52),(32,54,48),(48,55,50),(54,56,55),(48,54,55),(50,57,53),(55,58,57),(56,59,58),(55,57,50),
(55,56,58),(32,33,54),(54,60,56),(33,35,60),(33,60,54),(56,61,59),(60,62,61),(35,38,62),(60,61,56),(60,35,62),
(63,9,10),(64,8,9),(65,64,63),(63,64,9),(66,7,8),(67,66,64),(38,67,65),(66,8,64),(67,64,65),(68,16,7),
(69,15,16),(70,69,68),(68,69,16),(71,14,15),(72,71,69),(41,72,70),(71,15,69),(72,69,70),(73,22,14),(74,21,22),
(75,74,73),(73,74,22),(76,20,21),(77,76,74),(47,77,75),(76,21,74),(75,77,74),(78,28,20),(79,27,28),(80,79,78),
(78,79,28),(81,26,27),(82,81,79),(53,82,80),(81,27,79),(80,82,79),(83,31,26),(84,30,31),(85,84,83),(83,84,31),
(86,10,30),(87,86,84),(59,87,85),(86,30,84),(85,87,84),(40,41,70),(40,88,39),(88,70,68),(40,70,88),(39,67,38),
(88,66,67),(68,7,66),(39,88,67),(88,68,66),(46,47,75),(46,89,45),(89,75,73),(46,75,89),(45,72,41),(89,71,72),
(73,14,71),(45,89,72),(89,73,71),(52,53,80),(51,52,90),(90,80,78),(52,80,90),(51,77,47),(90,76,77),(76,78,20),
(51,90,77),(90,78,76),(58,59,85),(57,58,91),(91,85,83),(58,85,91),(57,82,53),(91,81,82),(81,83,26),(57,91,82),
(91,83,81),(62,38,65),(61,62,92),(92,65,63),(62,65,92),(61,87,59),(92,86,87),(86,63,10),(61,92,87),(92,63,86));

RandomArray:Array[0..255]of word=(
42995,13667,15106,18912,23214,63544,57718,34660,48200,33639
,28732,25944,43247,44767,62676,56393,60194,48369,51749,50740
,10182,46244,9186,15102,62218,64317,47772,22960,284,54100
,61846,18652,7966,41782,62429,26407,35838,16108,51309,4241
,58102,37474,26210,28234,31189,26914,10403,14012,8336,9891
,16361,18463,35350,46073,64320,35984,54060,2514,2861,39823
,56177,58902,64863,60290,31555,54815,53445,42897,51094,30137
,8753,25729,60749,36071,22698,21575,19396,40412,5008,46634
,54543,52001,25208,38831,1098,20543,51375,10048,44705,59201
,2786,12807,47362,58632,9827,38214,24318,52407,10742,43204
,32475,44971,41126,61380,21791,44562,53227,42999,22397,19777
,3447,60909,16440,34694,52638,40459,29864,53721,25058,7713
,20624,28610,18087,46480,1064,51281,41076,15990,3447,47406
,22927,7231,33865,61904,49270,62276,46021,58780,56344,37115
,47610,58979,44939,49814,13291,26167,9014,22037,9477,31627
,24846,23226,42429,10678,52818,22991,2397,64297,60215,13507
,27778,860,49620,49958,4537,14182,48793,33330,52370,55264
,4112,51109,30345,21439,55972,27655,11002,42821,715,52333
,48156,32233,9977,39662,49873,21043,14549,57066,64366,24577
,51111,6988,2787,17022,51459,31441,49157,27004,40066,33281
,33913,56253,32109,39746,28802,60034,45297,30068,17119,49261
,5135,10194,19513,466,54459,28926,56850,56048,39366,41008
,62865,18474,14900,58979,5588,18347,55094,11818,37781,27523
,8229,44697,57863,64691,49427,60370,29072,32091,38932,49013
,15826,23292,685,39546,17546,8205,22061,16749,21393,27738
,36870,34700,61681,31793,34982,58357);

var

LightPos:Array[0..3] of GLfloat = (40,30,40,0);
LightSpec:Array[0..3] of GLfloat = (0.7,0.7,0.7,0);
LightDiff:Array[0..3] of GLfloat = (1,1,1,0);

Dif:array[0..3] of GLfloat;

Loc:array[1..3] of GLfloat;

  ALBuffer : array [1..256] of TALuint;
  ALSource : array [1..256] of TALuint;
//  SourcePos: array [1..256,1..3] of TALfloat;
  SourceVel: array [1..256,1..3] of TALfloat;
  Listener:record
    Pos: array [1..3] of TALfloat;
    Vel: array [1..3] of TALfloat;
    Ori: array [1..6] of TALfloat;
  end;

implementation

uses Unit1;

function GetPresetColor(ID:integer):TColor;
begin
  ID := (ID-1) mod length(PresetColor) + 1;
  Result := PresetColor[ID,1] + PresetColor[ID,2] shl 8 + PresetColor[ID,3] shl 16;
end;

procedure SetPresetColorGL(ID:integer; A:single);
var IDn:integer;
begin
  IDn := (ID-1) mod length(PresetColor) + 1;
  if IDn = 0 then
    glColor4f(0,0,0,A)
  else
    glColor4f(PresetColor[IDn,1]/255,PresetColor[IDn,2]/255,PresetColor[IDn,3]/255,A)
end;


end.
